/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.unibo.as.client;

import java.io.Serializable;
import it.unibo.as.client.Common.SeedCard;



/**
 *
 * @author lilith
 */
public class Card implements Serializable
{
    public Common.SeedCard seed;
    public int number;

    @Deprecated
    private Card()
    {
        /*
        number = 5;
        seed = Common.SeedCard.NULL;
         * 
         */
    }
    

    public Card(int card) 
    {
        int nSeed = card & Common.SEED_MASK;
        
        switch(nSeed)
        {
            case Common.SEED_HEARTS:
                seed = Common.SeedCard.HEARTS;
                break;
            case Common.SEED_DIAMONDS:
                seed = Common.SeedCard.DIAMONDS;
                break;
            case Common.SEED_FLOWERS:
                seed = Common.SeedCard.FLOWERS;
                break;
            case Common.SEED_SPADES:
                seed = Common.SeedCard.SPADES;
                break;
            default:
                seed = Common.SeedCard.NULL;
                break;
        }
        
        number = card & Common.NUMBER_MASK;
    }

    public Card(Common.SeedCard seed, int number) 
    {
        this.seed = seed;
        this.number = number;
    }
    
    public int getCardDigit()
    {
        int nSeed = number;
        
        switch(seed)
        {
            case HEARTS:
                nSeed += Common.SEED_HEARTS;
                break;
            case DIAMONDS:
                nSeed += Common.SEED_DIAMONDS;
                break;
            case FLOWERS:
                nSeed += Common.SEED_FLOWERS;
                break;
            case SPADES:
                nSeed += Common.SEED_SPADES;
                break;
            case NULL:
                nSeed = -1;
                break;
        }
        
        return nSeed; 
    }
    
    
    public boolean isValid()
    {
        boolean bRet = true;
        if(seed == Common.SeedCard.NULL)
        {
            bRet = false;
        }
        
        return bRet;
    }
    
    
    @Override
    public String toString() 
    {
        String strSeed = "";
        String strNumber = "";
        
        switch(seed)
        {
            case HEARTS:
                strSeed = Common.HEARTS_TXT;
                break;
            case DIAMONDS:
                strSeed = Common.DIAMONDS_TXT;
                break;
            case FLOWERS:
                strSeed = Common.FLOWERS_TXT;
                break;
            case SPADES:
                strSeed = Common.SPADES_TXT;
                break;
        }
        
        switch(number)
        {
            case 0:
                strNumber = "A";
                break;
            case 10:
                strNumber = "J";
                break;
            case 11:
                strNumber = "Q";
                break;
            case 12:
                strNumber = "K";
                break;
            default:
                strNumber = "" + (number+1);
                break;
        }
        return strNumber + " " + strSeed;
    }

    public boolean compare(Card card)
    {
        boolean bRet = false;
        if((card.number == this.number) && (card.seed == this.seed))
        {
            bRet = true;
        }
        
        return bRet;
    }

    public int getNumber() {
        return number;
    }

    public SeedCard getSeed() {
        return seed;
    }

    public void setNumber(int n){
        this.number = n;
    }

    public void setSeed(Common.SeedCard seed){
        this.seed = seed;
    }

}
